import { ref, onMounted, onBeforeMount } from 'vue'
/**
 * 获取窗口滚动的位置
 * @returns x: 水平位置 y:垂直位置
 */
export function useWindowScroll () {
  const x = ref(0)
  const y = ref(0)
  const scroll = () => {
    x.value = document.documentElement.scrollLeft
    y.value = document.documentElement.scrollTop
  }
  onMounted(() => {
    document.addEventListener('scroll', scroll)
  })
  onBeforeMount(() => {
    document.removeEventListener('scroll', scroll)
  })
  return {
    x,
    y
  }
}
